package com.rdzn.mall.portal.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rdzn.mall.base.common.Result;
import com.rdzn.mall.center.entity.PmsBrand;
import com.rdzn.mall.center.service.IPmsBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
* @Description: pms_brand
* @Author: jeecg-boot
* @Date:   2020-08-27
* @Version: V1.0
*/
@Api(tags="pms_brand")
@RestController
@RequestMapping("/brand")
@Slf4j
public class MPmsBrandController extends JeecgController<PmsBrand, IPmsBrandService> {
   @Autowired
   private IPmsBrandService pmsBrandService;

   /**
    * 分页列表查询
    *
    * @param pmsBrand
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   @AutoLog(value = "pms_brand-分页列表查询")
   @ApiOperation(value="pms_brand-分页列表查询", notes="pms_brand-分页列表查询")
   @GetMapping(value = "/list")
   public Result<?> queryPageList(PmsBrand pmsBrand,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<PmsBrand> queryWrapper = QueryGenerator.initQueryWrapper(pmsBrand, req.getParameterMap());
       Page<PmsBrand> page = new Page<PmsBrand>(pageNo, pageSize);
       IPage<PmsBrand> pageList = pmsBrandService.page(page, queryWrapper);
       return Result.ok(pageList);
   }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "pms_brand-通过id查询")
    @ApiOperation(value="pms_brand-通过id查询", notes="pms_brand-通过id查询")
    @GetMapping(value = "/detail")
    public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
        PmsBrand pmsBrand = pmsBrandService.getById(id);
        if(pmsBrand==null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(pmsBrand);
    }

   /**
    *   添加
    *
    * @param pmsBrand
    * @return
    */
   @AutoLog(value = "pms_brand-添加")
   @ApiOperation(value="pms_brand-添加", notes="pms_brand-添加")
   @PostMapping(value = "/add")
   public Result<?> add(@RequestBody PmsBrand pmsBrand) {
       pmsBrandService.save(pmsBrand);
       return Result.ok("添加成功！");
   }

   /**
    *  编辑
    *
    * @param pmsBrand
    * @return
    */
   @AutoLog(value = "pms_brand-编辑")
   @ApiOperation(value="pms_brand-编辑", notes="pms_brand-编辑")
   @PutMapping(value = "/edit")
   public Result<?> edit(@RequestBody PmsBrand pmsBrand) {
       pmsBrandService.updateById(pmsBrand);
       return Result.ok("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "pms_brand-通过id删除")
   @ApiOperation(value="pms_brand-通过id删除", notes="pms_brand-通过id删除")
   @DeleteMapping(value = "/delete")
   public Result<?> delete(@RequestParam(name="id",required=true) String id) {
       pmsBrandService.removeById(id);
       return Result.ok("删除成功!");
   }

   /**
    *  批量删除
    *
    * @param ids
    * @return
    */
   @AutoLog(value = "pms_brand-批量删除")
   @ApiOperation(value="pms_brand-批量删除", notes="pms_brand-批量删除")
   @DeleteMapping(value = "/deleteBatch")
   public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
       this.pmsBrandService.removeByIds(Arrays.asList(ids.split(",")));
       return Result.ok("批量删除成功!");
   }


}
